//  实现所有与分类数据相关的业务
const cateModel = require('../models/cateModel.js')
//获取所有分类的数据
exports.getAllCate = (req,res) =>{
    cateModel.getAllCate((err,data)=>{
        if(err){
            res.end(JSON.stringify({code:400,msg:'数据查询失败'}))

        }else{
            res.end(JSON.stringify({code:200,msg:'数据查询成功',data}))
        }
    })
}

exports.categoriesById = (req,res) =>{
    let obj = req.query
    cateModel.categoriesById(obj,(err)=>{
        console.log('1444')
        if(err){
            res.json({code:400,msg:'修改失败'})
        }else{
            res.json({code:200,msg:'修改成功'})
        }
    })
}

exports.categoriesAdd = (req,res)=>{
    let obj = req.query
    cateModel.categoriesAdd(obj,(err)=>{
        if(err){
            res.json({code:400,msg:'添加失败'})
        }else{
            res.json({code:200,msg:'添加成功'})
        }
    })
}

exports.cateDelById = (req,res)=>{
    let id = req.query.id
    cateModel.cateDelById(id,(err)=>{
        if(err){
            res.json({code:400,msg:'删除失败！'})
        }else{
            res.json({code:200,msg:'删除成功！'})
        }
    })
}

exports.delCateById = (req,res)=>{
    let ids = req.query.id
    console.log(ids)
    cateModel.delCateById(ids,(err)=>{
        if(err){
            res.json({code:400,msg:'删除失败！'})
        }else{
            res.json({code:200,msg:'删除成功!'})
        }
    })
}